#ifndef GENERAL_FUNCTIONS
#define GENERAL_FUNCTIONS

#include <Winsock2.h>
#include <stdio.h>
#include "Types.h"


/*
 * Convert Mode Name To TMode
 * =========================
 * This function translates a string of a mode name to a specific mode 
 * Arguments: *mode - a string containing the name of the mode
 * Return Value: returns a TMODE type according to the name.
 */
TMode ConvertModeNameToTMode(char *mode);

/*
 * Notify Clock End Of Round
 * =========================
 * This function sends an "end of turn" message to the clock. 
 * Arguments: ClockSocket - A socket conecting the client to the clock server
 * Return Value: A Boolian Variable represnting a fiailed or successful transference.
 */
BOOL NotifyClockEndOfRound(SOCKET ClockSocket);

/*
 * Notify Interceptor position
 * =========================
 * This functios send a position vector to the interceptor 
 * Arguments: Interceptor Socket - A socket conecting the server to the interceptor
 * 			  Position - An X,Y position Vector
 * Return Value: A Boolian Variable represnting a fiailed or successful transference.
 */
BOOL NotifyInterceptorposition(SOCKET IntercptorSocket,TVector Position);



/*
 * Wait For Clock To Notify Beginning Of Round
 * =========================
 * This function holds progress of the proccess  until 
 * receiving a "beginning of round" message from the clock
 * Arguments: ClockSocket - A socket conecting the client to the clock server	  
 * Return Value: return an integer for the round number or -1 if failed
 */
int WaitForClockToNotifyBeginningOfRound(SOCKET ClockSocket);

/*
 * Identify To Server
 * =========================
 * This function sends its node type to a a server. 
 * Arguments: NodeType - a TMode represnting the what node it is
 * 			  Server Socket - a Socket to a server this node is a client of.
 * Return Value: Description
 */
void IdentifyToServer(TMode NodeType , SOCKET ServerSocket);


/*	CreateThreadSimple
 *  ------------------
 *	This function creates a thread by calling Win32 Api's CreateThread()
 *	function, and setting some of the parameters to default value. 
 *
 *	parameters:
 *	----------
 *	StartAddress - a pointer to the function that will be run by the thread.
 *	ParameterPtr - a pointer to the parameter that will be supplied to the 
 *                function run by the thread.
 *	ThreadIdPtr - return argument: a pointer to a DWORD variable into which 
 *               the function will write the created thread's ID.
 *
 *	returns:
 *	--------
 *	On success, a handle to the created thread. On Failure - NULL.
 */
HANDLE CreateThreadSimple(  LPTHREAD_START_ROUTINE StartAddress, LPVOID ParameterPtr, LPDWORD ThreadIdPtr );

/*
 * Print Action Type
 * =========================
 * For Debbuging this function prints what action is being sent. 
 * Arguments: Action-	A TAction for the action that is eing sent.
 * Return Value: None
 */
void PrintActionType(TActionType Action);

/*
 * Finished Start Up Sequence
 * =========================
 * This function is used for debugging- prints "FINISHED START UP SEQUENCE"  
 * Arguments: None
 * Return Value: None
 */
void FinishedStartUpSequence();

/*
 * Print Round Started
 * =========================
 * Debbuging function prints what round started. 
 * Arguments: Round number-	an integer representing what round it is
 * Return Value: None
 */
void PrintRoundStarted(int RoundNumber);

/*
 * Print Round Ended
 * =========================
 * Debbuging function, prints "round ended".  
 * Arguments: None
 * Return Value: None
 */
void PrintRoundEnded();

/*
 * Print End Of Game
 * =========================
 * Debbuging Function prints "End of game" 
 * Arguments: None
 * Return Value: None
 */
void PrintEndOfGame();

/*
 * Verify Num Of Args
 * =========================
 * This function Tells us if we have the right numberof arguments according to the mode,
 * prints the number of it received and the number it should and exits the program. 
 * Arguments: Mode		a Tmode showing what mode called the function.
 * 			  argc		an integer showing how many argument did the mode receive
 * Return Value: None
 */
void VerifyNumOfArgs (TMode Mode, int argc);

/*
 * Print Error And Exit
 * =========================
 * This function prints out what error occured. 
 * Arguments: Error-	a TError type showing what was the error.
 * 			  Name		Description
 * Return Value: None
 */
void PrintErrorAndExit(TError Error);

#endif